﻿namespace Papyrus.Web.Tests.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Papyrus.Web.Models.Entities;
    using Moq;
    using Papyrus.Web.Controllers;
    using System.Web.Mvc;
    using Papyrus.Web.Models;

    [TestClass]
    public class LoanControllerFixture
    {
        [TestMethod]
        public void ShouldRenderNewViewOnCreateAction()
        {
            var controller = new LoanController();

            var result = controller.Create();

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual("Create", ((ViewResult)result).ViewName);
        }

        [TestMethod]
        public void ShouldSaveNewLoan()
        {
            var loanViewModel = new LoanViewModel();
            loanViewModel.LoanDate = DateTime.Now - new TimeSpan(1, 0, 0, 0);
            loanViewModel.ReturnDate = DateTime.Now;
            var mockRepository = new Mock<ILoanRepository>();
            mockRepository.Setup(r => r.SaveLoan(It.Is<Loan>(l => l.LoanDate == loanViewModel.LoanDate && l.ReturnDate == loanViewModel.ReturnDate))).Verifiable();
            var controller = new LoanController(mockRepository.Object);

            var result = controller.Save(loanViewModel);

            mockRepository.Verify();
        }
    }
}
